//
//  SettingCell.m
//  WeiXin
//
//  Created by 亦心 on 15/12/7.
//  Copyright © 2015年 wwj. All rights reserved.
//

#import "SettingCell.h"
#import "SettingItem.h"
#import "SettingArrowItem.h"

@interface SettingCell ()

@property (weak, nonatomic) IBOutlet UIButton *contentButton;
@property (weak, nonatomic) IBOutlet UIButton *subButton;
@property (weak, nonatomic) IBOutlet UIImageView *arrowView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *leftMargin;

@end

@implementation SettingCell
+(instancetype)settingCellWithTableView:(UITableView *)tableView{
    static NSString *ID = @"SettingCell";
    SettingCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell == nil) {
        cell = [[NSBundle mainBundle] loadNibNamed:@"SettingCell" owner:nil options:nil].firstObject;
    }
    return cell;
}

-(void)setItem:(SettingItem *)item{
    _item = item;
    
    [self setItemData];
    [self setRightData];
}

-(void)setItemData{
    if (_item.icon) {
        [_contentButton setImage:[UIImage imageNamed:_item.icon] forState:UIControlStateNormal];
        _leftMargin.constant = 10;
    }else{
        _leftMargin.constant = 0;
    }
    [_contentButton setTitle:_item.title forState:UIControlStateNormal];
    
     _subButton.hidden = NO;
    if (_item.subTitle) {
        [_subButton setTitle:_item.subTitle forState:UIControlStateNormal];
    }
    if (_item.subImage){
        [_subButton setImage:[UIImage imageNamed:_item.subImage] forState:UIControlStateNormal];
    }else{
        _subButton.hidden = YES;
    }
}

-(void)setRightData{
    if ([_item isKindOfClass:[SettingArrowItem class]]) {
        _arrowView.hidden = NO;
    }else{
        _arrowView.hidden = YES;
    }
    
}


@end
